package com.zzz.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/*
 * @author zzr
 * @date: 2025/07/06  11:24
 * @description: 测试 ServletContext 的其他 API
 */
@WebServlet("/servlet5")
public class servlet5 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();

        // 获取一个指向项目部署位置下的某个文件目录的磁盘真实路径的 API
        String path = servletContext.getRealPath("upload");
        System.out.println(path + "\\test.html");

        // 项目部署的上下文路径 / 项目的访问路径
        String contextPath = servletContext.getContextPath();
        System.out.println(contextPath);
    }
}
